package com.liufanying.sikulix;

import com.liufanying.sikulix.view.CaiView;
import com.liufanying.sikulix.view.CategoryView;
import com.liufanying.sikulix.view.ImageView;
import com.liufanying.sikulix.view.OperateView;
import org.apache.log4j.helpers.DateTimeDateFormat;
import org.sikuli.script.*;

import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;


/**
 * 描述
 *
 * @author liufanying
 * @date 2023/5/10 10:20
 */
public class Application {

    public static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
    /**
     * 图片目录
     */
    public static final String IMG_PATH = System.getProperty("user.dir") + File.separator + "imgs" + File.separator;

    /**
     * 当前所处界面
     */
    public static Category CURRENT_CATEGORY;


    public static void main(String[] args) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        Screen SCREEN = new Screen();
        Application application = new Application();
        application.makeCai(SCREEN);
    }

    public void makeCai(Screen SCREEN){

        ImageView imageView = new ImageView();

        List<Pattern> cai = new ArrayList<>();
        cai.add(CaiView.hua);
        cai.add(CaiView.xiaomai);
        cai.add(CaiView.zuoliao);
        cai.add(CaiView.hua);
        cai.add(CaiView.hua);

        Region region = SCREEN.newRegion(50, 180, 500, 500);

        List<Match> click = new ArrayList<>();

        for (int i = 0; i < cai.size(); i++) {
            Pattern pattern = cai.get(i);
            Match exists = region.exists(pattern);
            if (exists != null) {
                System.out.println("找到商品");
                click.add(exists);
            }
        }


        while (true){
            for (Match match : click) {
                match.click();
            }


            SCREEN.newRegion(1500, 900, 200, 100).click();
            sleep(3800);
            SCREEN.newRegion(1500, 900, 200, 100).click();
        }

    }




    private void sleep(long s){
        try {
            Thread.sleep(s);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

}
